﻿// ===============================================================================
// DotNet.Platform 开发框架 2016 版权所有
// ===============================================================================

using System;
using System.Web.Mvc;
using DotNet.Edu.Entity;
using DotNet.Edu.Service;
using DotNet.Extensions;
using DotNet.Helper;
using DotNet.Utility;

namespace DotNet.EduWeb.Areas.Edu.Controllers
{
    public class AqpxFileController : EduController
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Grid(string key,string status,string industry_category, string user_category, string start_exam_date,string end_exam_date)
        {
            var list = EduService.AqpxFile.GetPageList(PageInfo(), key, status,industry_category, user_category, start_exam_date,end_exam_date);
            return View(list);
        }
        
        public ActionResult Audit(string id)
        {
            var entity = EduService.AqpxFile.Get(id);
            if (entity == null) return NotFound(id);
            return View("Audit", entity);
        }

        public ActionResult EditExamDate(string id)
        {
            var entity = EduService.AqpxFile.Get(id);
            if (entity == null) return NotFound(id);
            return View("EditExamDate", entity);
        }

        [HttpPost]
        public ActionResult AuditSave(AqpxFile entity)
        {
            var result = EduService.AqpxFile.Audit(entity);
            return Json(result);
        }

        [HttpPost]
        public ActionResult EditExamDateSave(AqpxFile entity)
        {
            var result = EduService.AqpxFile.UpdateExamDate(entity.id,entity.exam_date);
            return Json(result);
        }

        [HttpPost]
        public ActionResult Delete(string id)
        {
            EduService.AqpxFile.Delete(id.SplitToArray());
            return Json(BoolMessage.True);
        }

        public ActionResult Details(string id)
        {
            var entity = EduService.AqpxFile.Get(id);
            if (entity == null) return NotFound(id);
            return View(entity);
        }
        
        private ActionResult NotFound(string id)
        {
            return NotFound("获取 数据 错误", $"无法找到 主键 = {id} 的信息");
        }


        [HttpPost]
        public ActionResult UpdatePayStatus(string id)
        {
            var result = EduService.AqpxFile.UpdatePayStatus(id);
            return Json(result);
        }

        public ActionResult Export()
        {
            return Export(EduService.AqpxFile.GetList());
        }
    }
}
